(function (factory){
"use strict";
if(typeof define==='function'&&define.amd){
define(['jquery'], factory);
}else if(typeof module!=='undefined'&&module.exports){
module.exports=factory(require('jquery'));
}else{
factory(jQuery);
}}(function ($, undefined){
var widgetData=[];
var clientCountry='';
var isChatyInMobile=(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm(os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s)|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(|\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(|\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg(g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v)|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v)|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|)|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0, 4))) ? 1:0;
var defaultFontFamily=["System Stack", "Arial", "Tahoma", "Verdana", "Helvetica", "Times New Roman", "Trebuchet MS", "Georgia", "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"];
var chatyEnv='dev';
var isBoatUser=false;
var chatyHasTimeDelay=false;
var chatyMaxTimeInterval=0;
var chatyHasPageScroll=false;
var chatyHasExitIntent=false;
var chatyPageScrolls=[];
var chatyTimeInterval;
var chatyIntervalTime=0;
var lastScrollPer=0;
var customExtraCSS="";
var chatyHideTimeInterval;
var chatyHideIntervalTime=0;
var ariaLabel="";
function checkForChatySettings(){
chatyInterval=setInterval(function (){
if(typeof(chaty_settings)=="object"){
clearInterval(chatyInterval);
if(typeof chaty_settings=="object"&&(chaty_settings.data_analytics_settings!="on"||chaty_settings.data_analytics_settings=="off")){
isBoatUser=true;
}
if(isTrue(chaty_settings.has_chatway)){
$("body").addClass("csaas-has-chatway");
}
widgetData=chaty_settings.chaty_widgets;
checkForCountry();
}}, 1000)
}
$(document).ready(function (){
var botPattern="(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)";
var re=new RegExp(botPattern, 'i');
var userAgent=navigator.userAgent;
if(re.test(userAgent)){
isBoatUser=true;
}
if(isChatyInMobile){
$("body").addClass("cht-in-mobile");
}else{
$("body").addClass("cht-in-desktop");
}
if(isTrue(chaty_settings.has_chatway)){
$("body").addClass("csaas-has-chatway");
}
if(typeof chaty_settings=="undefined"){
console.log("Chaty settings doesn't exists");
checkForChatySettings()
}else if(chaty_settings.chaty_widgets.length==0){
console.log("Chaty widget doesn't exists");
}else{
widgetData=chaty_settings.chaty_widgets;
checkForCountry();
if(typeof chaty_settings=="object"&&chaty_settings.data_analytics_settings!="on"||chaty_settings.data_analytics_settings=="off"){
isBoatUser=true;
}}
if($(window).height() > $(window).width()){
$("body").addClass("cht-portrait").removeClass("cht-landscape");
}else{
$("body").addClass("cht-landscape").removeClass("cht-portrait");
}
$(document).on("click", "html, body", function (e){
if($(".chaty-popup-whatsapp-form.active").length){
$(".chaty-popup-whatsapp-form.active").each(function(){
var widgetId=$(this).data("widget");
var clickStatus=checkChatyCookieExpired(widgetId, "c-Whatsapp");
if((!isEmpty(widgetId)||widgetId==0)&&clickStatus){
saveChatyCookieString(widgetId, "c-Whatsapp");
}})
}
$(".form-open").removeClass("form-open");
$(".chaty-outer-forms").removeClass("active");
$(".chaty .chaty-widget.chaty-no-close-button:not(.has-single)").addClass("chaty-open");
if($(".chaty .chaty-widget").hasClass("chaty-open")){
$(".chaty .chaty-widget:not(.chaty-no-close-button)").removeClass("chaty-open");
$("body").removeClass("add-bg-blur-effect");
}
$("body").removeClass("add-bg-blur-effect");
chatySetCookie("hide-bg-blur-effect", true, 365);
hideDefaultOpenWidgets();
});
$(document).on("click", ".chaty, .chaty-outer-forms", function (e){
e.stopPropagation();
});
$(document).on("click", ".chaty.form-open .chaty-i-trigger.single-channel a", function (e){
$("body").removeClass("add-bg-blur-effect");
});
$(document).on("click", ".chaty.form-open .chaty-i-trigger.single-channel .chaty-cta-close", function (e){
$("body").removeClass("add-bg-blur-effect");
});
$(document).on("click", ".chaty-close-view-list", function(){
$(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
$("body").removeClass("add-bg-blur-effect");
chatySetCookie("hide-bg-blur-effect", true, 365);
hideDefaultOpenWidgets();
});
$(document).on("submit", ".whatsapp-chaty-form", function (){
if($(this).hasClass("form-google-analytics")){
var widgetChannel="Whatsapp";
if(window.hasOwnProperty("gtag")){
gtag("event", "chaty_" + widgetChannel, {
eventCategory: "chaty_" + widgetChannel,
event_action: "chaty_" + widgetChannel,
method: "chaty_" + widgetChannel
});
}
if(window.hasOwnProperty("ga")){
var ga_settings=window.ga.getAll()[0];
ga_settings&&ga_settings.send("event", "click", {
eventCategory: "chaty_" + widgetChannel,
eventAction: "chaty_" + widgetChannel,
method: "chaty_" + widgetChannel
})
}}
var widgetId=$(this).data('widget');
var chatyChannel=$(this).data('channel');
var clickStatus=checkChatyCookieExpired(widgetId, "c-" + chatyChannel);
if((!isEmpty(widgetId)||widgetId==0)&&clickStatus){
saveChatyCookieString(widgetId, "c-" + chatyChannel);
var widgetNonce=$("#chaty-widget-" + widgetId).data("nonce");
if(!isBoatUser){
$.ajax({
url: chaty_settings.ajax_url,
data: {
widgetId: widgetId,
userId: widgetId,
isMobile: isChatyInMobile,
channel: chatyChannel,
nonce: widgetNonce,
action: 'update_chaty_channel_click'
},
dataType: 'json',
method: 'post',
});
}}
if($("#chaty-widget-" + widgetId).length){
$("#chaty-widget-" + widgetId).removeClass("form-open");
$(this).closest(".chaty-outer-forms").removeClass("active");
if($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("cssas-no-close-button")){
$("#chaty-widget-" + widgetId).find(".chaty-widget:not(.has-single)").addClass("chaty-open")
}}
if($("body").hasClass("add-bg-blur-effect")){
$("body").removeClass("add-bg-blur-effect");
hideDefaultOpenWidgets();
}});
$(document).on("click", ".chaty-close-button, .chaty-close-agent-list, .whatsapp-form-close-btn", function (e){
e.preventDefault();
e.stopPropagation();
var widgetId=$(this).closest(".chaty-outer-forms").data('widget');
if(!isEmpty(widgetId)||widgetId==0){
if($("#chaty-widget-" + widgetId).length){
$("#chaty-widget-" + widgetId).removeClass("form-open");
$(this).closest(".chaty-outer-forms").removeClass("active");
if($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("chaty-no-close-button")){
$("#chaty-widget-" + widgetId).find(".chaty-widget:not(.has-single)").addClass("chaty-open");
}}
if($(this).closest(".chaty-whatsapp-btn-form").length){
var dataChannel=$(this).closest(".chaty-outer-forms").data('channel');
if(!isEmpty(dataChannel)){
var clickStatus=checkChatyCookieExpired(widgetId, "c-" + dataChannel);
if(clickStatus){
saveChatyCookieString(widgetId, "c-" + dataChannel);
}}
var visibleStatus=checkChatyCookieExpired(widgetId, 'v-widget');
if(visibleStatus){
updateWidgetViews(widgetId);
}}
if($(this).hasClass("whatsapp-form-close-btn")){
clickStatus=checkChatyCookieExpired(widgetId, "c-Whatsapp");
if((!isEmpty(widgetId)||widgetId==0)&&clickStatus){
saveChatyCookieString(widgetId, "c-Whatsapp");
}}
}
$("body").removeClass("add-bg-blur-effect");
});
$(document).on("keypress", '.chaty-contact-input input[type="tel"]', function(e){
var charCode=(e.which) ? e.which:e.keyCode;
if(charCode==43&&$(this).val()==""){
return true;
}
if(charCode >=48&&charCode <=57){
return true;
}
return false;
});
$(document).on("change", '.chaty-contact-input input[type="tel"]', function (){
var regex=new RegExp(/^(\+)?\d*$/);
var phone_number=$(this).val();
if(!regex.test(phone_number)){
$(this).val("");
}});
$(document).on("click", "a.chaty-qr-code-form", function (e){
e.preventDefault();
var dataForm=$(this).data('form');
if(!isEmpty(dataForm)){
if($("#" + dataForm).length){
var buttonHtml=$(this).html();
if($("#" + dataForm).hasClass("active")){
$(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open");
$(this).closest(".chaty").removeClass("form-open");
$("#" + dataForm).removeClass("active");
$("body").removeClass("add-bg-blur-effect");
}else{
$(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
$(this).closest(".chaty").addClass("form-open");
$("#" + dataForm).addClass("active");
buttonHtml=$(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html();
$(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
}}
}});
$(document).on("click", "a.chaty-contact-us-form", function (e){
e.preventDefault();
var dataForm=$(this).data('form');
if(!isEmpty(dataForm)){
if($("#" + dataForm).length){
if(googleV3Token!=""){
googleV3Token="";
refreshG3Token();
}
if($("#" + dataForm).hasClass("active")){
$(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open");
$(this).closest(".chaty").removeClass("form-open");
$("#" + dataForm).removeClass("active");
$("body").removeClass("add-bg-blur-effect");
}else{
$(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
$(this).closest(".chaty").addClass("form-open");
$("#" + dataForm).addClass("active");
$("#" + dataForm).find(".chaty-ajax-success-message").remove();
$("#" + dataForm).find(".chaty-ajax-error-message").remove();
$("#" + dataForm).find(".has-chaty-error").removeClass("has-chaty-error");
buttonHtml=$(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html();
$(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
}}
}});
$(document).on("click", "a.chaty-whatsapp-btn-form", function (e){
e.preventDefault();
var dataForm=$(this).data('form');
if(!isEmpty(dataForm)){
if($("#" + dataForm).length){
if($("#" + dataForm).hasClass("active")){
$(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open");
$(this).closest(".chaty").removeClass("form-open");
$("#" + dataForm).removeClass("active");
$("body").removeClass("add-bg-blur-effect");
setTimeout(function(){
$("body").removeClass("add-bg-blur-effect");
}, 100);
}else{
$(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
$(this).closest(".chaty").addClass("form-open");
$("#" + dataForm).addClass("active");
var buttonHtml=$(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html();
$(this).closest(".chaty").find(".chaty-widget").find(".open-chaty-channel").html(buttonHtml);
}
setTimeout(function(){
$(".chaty-whatsapp-btn-form.active .chaty-whatsapp-input").focus();
}, 100);
}}
});
$(document).on("click", ".chaty-channel.chaty-agent-button", function (e){
e.preventDefault();
var dataForm=$(this).data('form');
if(!isEmpty(dataForm)){
if($("#" + dataForm).length){
if(!$(this).closest(".chaty").find(".chaty-widget").hasClass("has-single")){
var buttonHtml=$(this).html();
$("#" + dataForm).addClass("is-active");
$(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
$(this).closest(".chaty").addClass("form-open");
$("#" + dataForm).addClass("active");
buttonHtml=$(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html();
$(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
}else{
if($(this).closest(".chaty").hasClass("form-open")){
$(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open");
$(this).closest(".chaty").removeClass("form-open");
$("#" + dataForm).removeClass("active");
$("body").removeClass("add-bg-blur-effect");
}else{
buttonHtml=$(this).closest(".chaty").find(".chaty-widget .chaty-cta-close").find("button").html();
$("#" + dataForm).addClass("is-active");
$(this).closest(".chaty").find(".chaty-widget").removeClass("chaty-open");
$(this).closest(".chaty").addClass("form-open");
$("#" + dataForm).addClass("active");
$(this).closest(".chaty").find(".open-chaty-channel").html(buttonHtml);
}}
}}
});
$(document).on("click", ".chaty-channel a.has-gae", function (e){
var widgetChannel=$(this).closest(".chaty-channel").data("channel");
if(widgetChannel!==undefined&&widgetChannel!=""&&widgetChannel!=null){
if(window.hasOwnProperty("gtag")){
gtag("event", "chaty_" + widgetChannel, {
eventCategory: "chaty_" + widgetChannel,
event_action: "chaty_" + widgetChannel,
method: "chaty_" + widgetChannel
});
}
if(window.hasOwnProperty("ga")){
var ga_settings=window.ga.getAll()[0];
ga_settings&&ga_settings.send("event", "click", {
eventCategory: "chaty_" + widgetChannel,
eventAction: "chaty_" + widgetChannel,
method: "chaty_" + widgetChannel
})
}}
});
$(document).on("mouseover", ".chaty-widget.has-single .chaty-channel a.has-on-hover[data-hover]", function (){
$(this).find(".on-hover-text").html($(this).data("hover"));
}).on("mouseleave", ".chaty-widget.has-single .chaty-channel a.has-on-hover[data-text]", function (){
$(this).find(".on-hover-text").html($(this).data("text"));
});
$(document).on("submit", ".whatsapp-chaty-form.has-form-gae", function(){
var widget_id=$(this).data("widget");
var widgetChannel=$("#Whatsapp-"+ widget_id +"-channel").data("channel");
if(widgetChannel!==undefined&&widgetChannel!=""&&widgetChannel!=null){
if(window.hasOwnProperty("gtag")){
gtag("event", "chaty_whatsapp_redirect", {
eventCategory: "chaty_whatsapp_redirect",
event_action: "chaty_whatsapp_redirect",
method: "chaty_whatsapp_redirect"
});
}
if(window.hasOwnProperty("ga")){
var ga_settings=window.ga.getAll()[0];
ga_settings&&ga_settings.send("event", "click", {
eventCategory: "chaty_whatsapp_redirect",
eventAction: "chaty_whatsapp_redirect",
method: "chaty_whatsapp_redirect"
})
}}
});
$(document).on("click", ".chaty-i-trigger:not(.single-channel)", function (){
if($(this).closest(".chaty").hasClass("form-open")){
$(this).closest(".chaty").removeClass("form-open");
$(this).closest(".chaty-widget:not(.has-single)").addClass("chaty-open");
}else{
$(this).closest(".chaty-widget").toggleClass("chaty-open");
}
$(".chaty-outer-forms.active").each(function(){
$(this).removeClass("active");
var widgetID=$(this).data("widget");
$("#chaty-widget-"+widgetID).removeClass("form-open");
});
if($(this).closest(".chaty").find(".chaty-widget").hasClass("chaty-no-close-button")){
$(this).closest(".chaty").find(".chaty-widget:not(.has-single)").addClass("chaty-open");
}});
$(document).on("click", ".chaty-i-trigger.single-channel .chaty-cta-close", function (){
if($(this).closest(".chaty").hasClass("form-open")){
$(this).closest(".chaty").removeClass("form-open");
var chatyWidgetId=$(this).closest(".chaty").data("id");
if($("#chaty-form-"+chatyWidgetId+"-Whatsapp").length&&$("#chaty-form-"+chatyWidgetId+"-Whatsapp").hasClass("active")){
clickStatus=checkChatyCookieExpired(chatyWidgetId, "c-Whatsapp");
if((!isEmpty(chatyWidgetId)||chatyWidgetId==0)&&clickStatus){
saveChatyCookieString(chatyWidgetId, "c-Whatsapp");
}}
}
$(".chaty-outer-forms.active").each(function(){
$(this).removeClass("active");
var widgetID=$(this).data("widget");
$("#chaty-widget-"+widgetID).removeClass("form-open");
});
});
if(!isChatyInMobile){
$(document).on("mouseover", "body:not(.chaty-in-mobile) .chaty.open-on-hover .chaty-i-trigger:not(.single-channel)", function (){
if(!$(this).closest(".chaty-widget").hasClass("chaty-open")&&!$(this).closest(".chaty-widget").hasClass("on-chaty-widget")){
$(this).closest(".chaty-widget").addClass("on-chaty-widget");
$(this).find(".chaty-cta-main").trigger("click");
}}).on("mouseleave", "body:not(.chaty-in-mobile) .chaty.open-on-hover .chaty-i-trigger:not(.single-channel)", function (){
if(!$(this).closest(".chaty-widget").hasClass("chaty-open")){
$(this).closest(".chaty-widget").removeClass("on-chaty-widget")
}});
}
$(document).on("click", ".chaty-channel.single a", function(){
var chatyWidgetId=$(this).closest(".chaty").data("id");
if($(this).closest(".chaty").hasClass("first_click")){
$(this).closest(".chaty-channel").removeClass("active");
}
removeChatyAnimation(chatyWidgetId);
});
$(document).on("click", ".chaty-chatway-channel", function (){
if(typeof(window.$chatway)=='object'){
window.$chatway.openChatwayWidget()
}});
$(document).on("click", ".chaty-channel a, .chaty-channel button", function (e){
var clickStatus;
var chatyChannel;
var chatyChannels=[];
var isSingle=0;
var chatyWidgetIdentifier;
var chatyWidgetId=$(this).closest(".chaty").data("id");
if(typeof chatyWidgetId!='undefined'){
chatyWidgetIdentifier=$("#chaty-widget-" + chatyWidgetId).data("identifier");
if(typeof chatyWidgetIdentifier!='undefined'){
var userId=$("#chaty-widget-" + chatyWidgetId).data("user");
removeChatyAnimation(chatyWidgetId);
if($(this).closest(".chaty-channel").hasClass("chaty-cta-main")||$(this).closest(".chaty-channel").hasClass("chaty-cta-close")){
if($("#chaty-form-"+chatyWidgetId+"-Whatsapp").length&&$("#chaty-form-"+chatyWidgetId+"-Whatsapp").hasClass("active")){
clickStatus=checkChatyCookieExpired(chatyWidgetId, "c-Whatsapp");
if((!isEmpty(chatyWidgetId)||chatyWidgetId==0)&&clickStatus){
saveChatyCookieString(chatyWidgetId, "c-Whatsapp");
}}
clickStatus=checkChatyCookieExpired(chatyWidgetId, 'c-widget');
$("#chaty-widget-" + chatyWidgetId).find(".ch-pending-msg").remove();
if(clickStatus){
saveChatyCookieString(chatyWidgetId, "c-widget");
if($(this).closest(".chaty-channel").hasClass("chaty-cta-main")){
chatyChannels=[];
if($("#chaty-widget-" + chatyWidgetId).hasClass("chaty-has-chat-view")){
$(".chaty-chat-view.chaty-chat-view-" + chatyWidgetId + " .chaty-view-channels").find(".chaty-channel").each(function (){
chatyChannel=$(this).data("channel");
clickStatus=checkChatyCookieExpired(chatyWidgetId, "v-" + chatyChannel);
if(clickStatus&&typeof chatyChannel!='undefined'){
saveChatyCookieString(chatyWidgetId, "v-" + chatyChannel);
chatyChannels.push(chatyChannel);
}});
}else{
$("#chaty-widget-" + chatyWidgetId + " .chaty-channel-list").find(".chaty-channel").each(function (){
chatyChannel=$(this).data("channel");
clickStatus=checkChatyCookieExpired(chatyWidgetId, "v-" + chatyChannel);
if(clickStatus&&typeof chatyChannel!='undefined'){
saveChatyCookieString(chatyWidgetId, "v-" + chatyChannel);
chatyChannels.push(chatyChannel);
}});
}
var widgetNonce=$("#chaty-widget-" + chatyWidgetId).data("nonce");
if(!isBoatUser){
$.ajax({
url: chaty_settings.ajax_url,
data: {
widgetId: chatyWidgetId,
userId: userId,
isMobile: isChatyInMobile,
channels: chatyChannels,
isSingle: 0,
nonce: widgetNonce,
action: 'update_chaty_widget_click'
},
dataType: 'json',
method: 'post',
});
}}
}
if($("#chaty-widget-" + chatyWidgetId).hasClass("first_click")){
$("#chaty-widget-" + chatyWidgetId + " .chaty-cta-main").removeClass("active");
$("#chaty-widget-" + chatyWidgetId + " .chaty-cta-main").removeClass("chaty-tooltip");
}}else if($(this).closest(".chaty-channel").hasClass("single")){
$("#chaty-widget-" + chatyWidgetId).find(".ch-pending-msg").remove();
clickStatus=checkChatyCookieExpired(chatyWidgetId, 'c-widget');
var widgetNonce=$("#chaty-widget-" + chatyWidgetId).data("nonce")
if(clickStatus){
saveChatyCookieString(chatyWidgetId, 'c-widget');
isSingle=0;
chatyChannels=[];
chatyChannel=$(this).closest(".chaty-channel").data("channel");
clickStatus=checkChatyCookieExpired(chatyWidgetId, "c-" + chatyChannel);
if(clickStatus){
chatyChannels.push(chatyChannel);
isSingle=1;
}
if(!isBoatUser){
$.ajax({
url: chaty_settings.ajax_url,
data: {
widgetId: chatyWidgetId,
userId: userId,
isMobile: isChatyInMobile,
channels: chatyChannels,
isSingle: isSingle,
nonce: widgetNonce,
action: 'update_chaty_widget_click'
},
dataType: 'json',
method: 'post',
});
}}
if($("#chaty-widget-" + chatyWidgetId).hasClass("first_click")){
$("#chaty-widget-" + chatyWidgetId + " .chaty-tooltip").removeClass("chaty-tooltip");
$("#chaty-widget-" + chatyWidgetId + " .single-channel a").addClass("chaty-tooltip");
}}else if($(this).hasClass("chaty-link")){
chatyChannel=$(this).closest(".chaty-channel").data("channel");
clickStatus=checkChatyCookieExpired(chatyWidgetId, "c-" + chatyChannel);
if(clickStatus){
saveChatyCookieString(chatyWidgetId, "c-" + chatyChannel);
var widgetNonce=$("#chaty-widget-" + chatyWidgetId).data("nonce");
if(!isBoatUser){
$.ajax({
url: chaty_settings.ajax_url,
data: {
widgetId: chatyWidgetId,
userId: userId,
isMobile: isChatyInMobile,
channel: chatyChannel,
nonce: widgetNonce,
action: 'update_chaty_channel_click'
},
dataType: 'json',
method: 'post',
});
}}
}}
}});
$(document).on("submit", ".chaty-ajax-contact-form", function (e){
e.preventDefault();
var inputErrorCounter=0;
$(this).find(".has-chaty-error").each(function (){
$(this).removeClass("has-chaty-error");
});
$(this).find(".chaty-error-msg").remove();
$(this).find(".chaty-ajax-error-message").remove();
$(this).find(".chaty-ajax-success-message").remove();
$(this).find(".is-required").each(function (){
if(jQuery.trim($(this).val())==""){
inputErrorCounter++;
$(this).addClass("has-chaty-error");
if($(this).hasClass("chaty-text-block")){
$(this).closest(".chaty-contact-input").find(".mce-tinymce").addClass("mce-error");
}}
});
if(inputErrorCounter==0){
var $form=$(this);
var form=$form[0];
var data=new FormData(form);
$(".chaty-submit-button").attr("disabled", true);
$("#chaty-submit-button-"+ $form.data("index") + " .chaty-loader").addClass("active");
jQuery.ajax({
url: chaty_settings.ajax_url,
enctype: 'multipart/form-data',
data: data,
type: 'post',
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function (response){
if(googleV3Token!=""){
googleV3Token="";
refreshG3Token();
}
$(".chaty-ajax-error-message").remove();
$(".chaty-ajax-success-message").remove();
$(".chaty-submit-button").attr("disabled", false);
if(response.status==1){
$("#chaty-submit-button-"+ $form.data("index") + " .chaty-loader").removeClass("active");
$(".chaty-contact-inputs").append("
" + response.message + "
");
$(".chaty-ajax-contact-form").find(".chaty-contact-input .mce-tinymce").removeClass("mce-error");
$(".field-name, .field-email, .field-message, .field-phone").val("");
$(".chaty-ajax-contact-form").find(".chaty-input-field").val("");
$(".chaty-ajax-contact-form").find(".chaty-textarea-field").val("");
$("#"+$form.find(".chaty-text-block").attr("id")+"_ifr").contents().find("body").html("");
if(response.redirect_action=="yes"){
if(response.link_in_new_tab=="yes"){
var openInNewTab=window.open(response.redirect_link, '_blank');
if(openInNewTab==null){
window.open(response.redirect_link);
}}else{
window.location=response.redirect_link;
}}
if(response.close_form_after=="yes"){
setTimeout(function (){
if($(".chaty-outer-forms.active").length){
var widgetId=$(".chaty-outer-forms.active").data('widget');
if(!isEmpty(widgetId)||widgetId==0){
if($("#chaty-widget-" + widgetId).length){
$("#chaty-widget-" + widgetId).removeClass("form-open");
$("body").removeClass("add-bg-blur-effect");
$(".chaty-outer-forms.active").removeClass("active");
if($("#chaty-widget-" + widgetId).find(".chaty-widget").hasClass("chaty-no-close-button")){
$("#chaty-widget-" + widgetId).find(".chaty-widget:not(.has-single)").addClass("chaty-open")
}}
}}
}, parseInt(response.close_form_after_seconds) * 1000);
}}else if(response.error==1){
if(response.errors.length){
for (var i=0; i < response.errors.length; i++){
$("." + response.errors[i].field).addClass("has-chaty-error");
$("." + response.errors[i].field).after("" + response.errors[i].message + "");
}}
$(".chaty-loader").removeClass("active");
}else if(response.status==0){
$(".chaty-contact-inputs").append("" + response.message + "
");
$(".chaty-loader").removeClass("active");
}
$(".email_suggestion").html('');
}});
}else{
$(".has-chaty-error:first").focus();
}
return false;
});
$(document).on('blur','.chaty-contact-form-box .field-email', function(event){
var widget_id=$(this).closest(".chaty-contact-form-box").data("widget");
$(this).mailcheck({
suggested: function(element, suggestion){
$('#email_suggestion'+widget_id).html("Did you mean " + suggestion.full + "?");
},
empty: function(element){
$('#email_suggestion'+widget_id).html('');
}});
});
if($(".chaty-contact-form-box .field-email").length){
$(".chaty-contact-form-box .field-email").emailautocomplete({
domains: ["protonmail.com", "yahoo.com", "gmail.com"]
});
}
$(document).on("click", ".email_suggestion i", function (){
$(this).closest(".chaty-contact-form-box").find(".field-email").val($(this).text()).focus();
jQuery(this).closest(".email_suggestion").html('');
});
$(document).on("click", ".chaty-widget.has-single .chaty-i-trigger .chaty-channel:not(.chaty-agent-button).Phone-channel", function (){
window.location=$(this).find("a").prop("href");
});
$(document).on("click", ".chaty-widget.has-single .chaty-i-trigger .chaty-channel:not(.chaty-agent-button).Phone-channel a, .picmo__popupContainer", function (e){
e.stopPropagation();
e.stopImmediatePropagation();
});
$(document).on("click", ".chaty-wp-emoji-input", function (){
if($(".picmo__popupContainer").length){
}else{
const {createPopup}=window.picmoPopup;
const trig=document.querySelector("#chaty_whatsapp_input");
const picker=createPopup({}, {
referenceElement: trig,
triggerElement: trig,
position: 'top',
hideOnEmojiSelect: false
});
picker.toggle();
picker.addEventListener('emoji:select', (selection)=> {
$('.chaty-whatsapp-input').val($(".chaty-whatsapp-input").val() + selection.emoji);
});
}});
$(document).on("click", "#chaty_whatsapp_input", function (){
if($(".picmo__popupContainer").length){
$(".picmo__popupContainer").remove();
}});
});
function setChatyEditor(){
if($(".chaty-text-block:not(.editor-loaded)").length){
$(".chaty-text-block:not(.editor-loaded)").each(function(){
text_id=$(this).attr("id");
wp.editor.initialize(text_id,
{
tinymce: {
wpautop: false,
toolbar1: 'bold italic underline',
},
quicktags: false
}
);
})
}}
$(window).resize(function(){
if($(window).height() > $(window).width()){
$("body").addClass("cht-portrait").removeClass("cht-landscape");
}else{
$("body").addClass("cht-landscape").removeClass("cht-portrait");
}});
function removeChatyAnimation(widgetId){
if($("#chaty-widget-" + widgetId).data("animation")!=undefined&&$("#chaty-widget-" + widgetId).data("animation")!="none"){
var animationClass="chaty-animation-" + $("#chaty-widget-" + widgetId).data("animation");
$("#chaty-widget-" + widgetId + " ." + animationClass).removeClass(animationClass);
}
$("#chaty-widget-" + widgetId+ " .ch-pending-msg").remove();
}
function checkForCountry(){
var hasCountryFilter=false;
if(widgetData.length){
$.each(widgetData, function (key, widgetRecord){
if(isTrue(widgetRecord.triggers.has_countries)&&!isEmpty(widgetRecord.triggers.countries)&&widgetRecord.triggers.countries.length){
hasCountryFilter=true;
}});
}
if(hasCountryFilter){
clientCountry=getUserCountry();
if(clientCountry!=''){
startMakingWidgets();
}else{
getClientCountry();
}}else{
startMakingWidgets();
}}
function getClientCountry(){
var $ipurl='https://www.cloudflare.com/cdn-cgi/trace';
$.get($ipurl, function (cloudflaredata){
var currentCountry=cloudflaredata.match("loc=(.*)");
if(currentCountry.length > 1){
currentCountry=currentCountry[1];
if(currentCountry){
currentCountry=currentCountry.toUpperCase();
if(currentCountry==""){
currentCountry="-";
}
setUserCountry(currentCountry);
startMakingWidgets();
}}
});
}
function startMakingWidgets(){
if(widgetData.length){
$("body").append('